/*
 * Copy Right: Tencent ISUX
 * Project: QAM（Qzone模块化页面搭建平台）
 * Description: 模块、组件、框架管理
 * Author: kundy
 * date: 2011-12-5
 */

var global_id=functions.getRequest("id")*1;
var global_type=functions.getRequest("type")*1;
var global_action=functions.getRequest("action");

parent.nav_set(2+global_type*1);

var page = {
	init:function(){
		if(global_type=="1"){
			$('#page_title').html("<i class=\"ico ico_manage\"></i><span>管理框架</span>");
		}
		else{
			$('#page_title').html("<i class=\"ico ico_manage\"></i><span>管理页面</span>");
		}
		$("#btn_add").click(function(){window.location.href="page.htm"});
		$("#btn_filter").click(function(){page.filter();});
		$("#btn_reset").click(function(){page.filterReset();});
		$("#page_up").click(function(){page.list_page(-1);});
		$("#page_down").click(function(){page.list_page(1);});
	},
	
	addInit:function(){
		if(global_action=="edit"){
			$("#btn_save").click(function(){page.update();});
			$('#page_title').html("<i class=\"ico ico_manage\"></i><span>修改页面</span>");
		}
		else if(global_type==1){//框架
			$("#btn_save").click(function(){page.add();});
			$('#page_title').html("<i class=\"ico ico_project_add\"></i><span>添加框架</span>");
		}
		else{
			$("#btn_save").click(function(){page.add();});
			$('#page_title').html("<i class=\"ico ico_project_add\"></i><span>添加页面</span>");
			
			$("#name").focusout(function () {
				this.value=this.value.replace(/\s/g,'');
				page.checkName(this.value);
			});
		}
		
		$("#btn_cancel").click(function(){window.location.href="page_manage.htm?type="+global_type});
		
		
		//不允许输入空格
		//鼠标离开、复制等！
		$("#name").mouseout(function () {
			this.value=this.value.replace(/\s/g,'');
		});
		
		$("#name").keyup(function () {
			this.value=this.value.replace(/\s/g,'');
		});
		$("#name").focusin(function () {
			$("#fhint_area_name").hide();
		});
		
		$(".textarea_style").focus(function(){
			$(this).addClass("textarea_focus")
			});
		$(".textarea_style").blur(function(){
			$(this).removeClass("textarea_focus")
			});
	},

	
	/*------------ 检查用户输入的名称 ------------*/
	checkName : function(name){
		if(name==""){
			$("#fhint_area_name").show();
			$("#fhint_area_name").removeClass('fhint_succeed').addClass('fhint_error');
			$("#fhint_ico").removeClass('ico_succeed').addClass('ico_error');
			$("#fhint_text").text("亲，名称要填的");
		}
    },
	
   
	
	
	search:function(){
		$('#parent_id_name').html("所有"+code_text);
		$('#parent_id').val(0);
		this.search_data=[];
		this.page=1;
		var search_text=$("#search_text").val();
		this.search_data.push([ "search_flag" , 1 ]);
		this.search_data.push([ "search_data" , search_text ]);
		this.showlist();
	},
	
	filter:function(){
		var project_id=$('#parent_id').val();
		if($("#sub_id").val()!=-1)project_id=$('#sub_id').val();
		this.search_data=[];
		this.page=1;
		if(project_id*1!=-1){
			this.search_data.push([ "search_flag" , 0 ]);
			this.search_data.push([ "project_id" , project_id ]);
		}
		this.showlist();
	},
	
	filterReset:function(){
		$('#parent_id_name').html("所有项目");
		$('#parent_id').val(0);
		$('#sub_id_name').html("选择子项目");
		$('#sub_id').val(0);
		this.search_data=[];
		this.page=1;
		this.showlist();
	},
    /*------------ 获取所有根项目信息 ------------*/
	search_data:[],
	page:1,//第几页
	reqnum:5,//每页显示多少条
	order:"id",//排序字段
	desc:1,//反序,0或空正常排序，1反序
	page_nums:0,//总页数
	
	
    showlist : function(t){
		var data_area=[];
		data_area.push([ "page" , page.page ]);
		data_area.push([ "reqnum" , page.reqnum ]);
		data_area.push([ "order" , page.order ]);
		data_area.push([ "desc" , page.desc ]);
		data_area.push([ "desc" , page.desc ]);
		if(this.search_data.length>0)
			data_area=data_area.concat(this.search_data);
		
		var data_str=functions.requestToString(data_area);
		if(global_type=="1")url_parm='page-frameShowlist';
		else url_parm='page-showlist';
        $.ajax({
                url: cgipath+url_parm, type: 'POST',data: data_str,dataType: 'json', timeout: ajax_timeout,error: function(){notify.show(2,"请求数据失败，请刷新页面");},
                success:this.handleShowlist
        });
    },
	
     handleShowlist : function(feedback){
        if(feedback.ret=="0"){
            //显示项目列表
            var listdata=feedback.listdata;
			var innerhtml="";
            for(var i=0;i<listdata.length;i++){
				innerhtml+="<tr>";
				if(listdata[i].thumb!=null)
					innerhtml+="<td class=\"td_thumbnails\"><div class=\"img_wrap\"><a href=\""+(cgipath+listdata[i].addr)+"\" title=\""+listdata[i].info+"\" target=\"_blank\"><img src=\""+cgipath+listdata[i].thumb+"?"+Math.floor(Math.random()*10000)+"\" alt=\"\"></a><span class=\"module_name\">"+listdata[i].name+"</span></div></td>";
				else
					innerhtml+="<td class=\"td_thumbnails\"><div class=\"img_wrap\"><a href=\"javascript:void(0)\" title=\""+listdata[i].info+"\" target=\"_blank\"><img src=\"css/sample/no_img.png\" alt=\"\"></a><span class=\"module_name\">"+listdata[i].name+"</span></div></td>";
				innerhtml+="<td>"+listdata[i].ident+"</td>";
				innerhtml+="<td>"+listdata[i].project_name+"</td>";
				innerhtml+="<td>"+listdata[i].author+"</td>";
				innerhtml+="<td><span class=\"txt_auxiliary\">"+listdata[i].adjust_time+"</span></td>";
				innerhtml+="<td>";
				innerhtml+="<a href=\"page.htm?type="+global_type+"&action=edit&id="+listdata[i].id+"\"><i class=\"ico ico_edit\"></i>修改</a> ";
				innerhtml+="<a href='javascript:void(0);' class=\"op_sub_href\" onclick=\"page.delConfirm("+listdata[i].id+");\" ><i class=\"ico ico_del\"></i>删除</a><BR>";
				
				innerhtml+="</tr>";
            }
			//翻页组件
			page.page_nums=Math.ceil(feedback.nums/page.reqnum);
			if(page.page_nums<page.page)page.page=page.page_nums;//防止page_nums等于0的情况
			$("#page_nums").html(page.page+"/"+page.page_nums);
			if(page.page==1)
				$("#page_up").removeClass("ico_page_left").addClass("ico_page_left_n");
			else
				$("#page_up").removeClass("ico_page_left_n").addClass("ico_page_left");
			if(page.page_nums==page.page)
				$("#page_down").removeClass("ico_page_right").addClass("ico_page_right_n");
			else
				$("#page_down").removeClass("ico_page_right_n").addClass("ico_page_right");
				
			$("#list_area").html(innerhtml);
        }
        else{
             message.show("message_div","",feedback.msg,4);
        }
    },
	
	list_page:function(t,order){
		if(order!=undefined && order!="")
		{
			page.order=order;
			if(page.desc*1==1)page.desc=0;
			else page.desc=1;
		}
	
		page.page=page.page-(-1)*t;
		if(page.page<=0)page.page=1;
		else if(page.page>page.page_nums) page.page=page.page_nums;
		page.showlist();
	},
	
	project_data:[],
	loadProject:function(){
		var data_area=[];
		var data_str=functions.requestToString(data_area);
        $.ajax({
                url: cgipath+'project-showStruct',type: 'POST',data: data_str,dataType: 'json',timeout: ajax_timeout,error: function(){notify.show(2,"请求数据失败，请刷新页面");},
                success:function(feedback){
					page.project_data=feedback.listdata;
					if(global_action=="edit")
						page.edit();
					
					page.parentList()
				}
        });
	},
	

	/*------------ 获取所有父项目信息ID列表 ------------*/
     parentList : function(){
		//显示父项目列表
		var ul="<ul>";
		if(global_action!="edit" && global_action!="add"){
			ul+="<li><a onclick=\"page.chooseParentId(-1)\" id=\"0\" name=\"所有项目\" href=\"javascript:void(0);\">所有项目</a></li>";
			ul+="<li><a onclick=\"page.chooseParentId(-2)\" id=\"0\" name=\"临时新建页面\" href=\"javascript:void(0);\">临时新建页面</a></li>";
		}
		console.log(page.project_data);
		for(var i=0;i<page.project_data.length;i++){
			ul+="<li><a onclick=\"page.chooseParentId("+i+")\" id=\""+page.project_data[i].parent.id+"\" name=\""+page.project_data[i].parent.name+"\" href=\"javascript:void(0);\">"+page.project_data[i].parent.name+"</a></li>";
		}
		ul+="</ul>";
		$("#parent_id_list").html(ul);
		$(".like_select").click(function(){$(this).parent().find('.select_drop_down').css({visibility: "visible",display: "none"}).show();});
		$(".type_select").hover(
			function(){},
			function(){$(this).find('.select_drop_down').hide();}
		);
    },
	chooseParentId : function(t){
         $('#parent_id_list').css('display', 'none');
		 $('#sub_id_name').html("选择子项目");
		 $('#sub_id').val(-1);
		 if(t==-1){
			$('#parent_id_name').html("所有项目");
			$('#parent_id').val(-1);
		 }
		 else if(t==-2){
			$('#parent_id_name').html("临时新建页面");
			$('#parent_id').val(1);
		 }
		 else{
			$('#parent_id_name').html(page.project_data[t].parent.name);
			$('#parent_id').val(page.project_data[t].parent.id);
			this.subProjectList(t);
		}
    },
	/*------------ 获取子项目信息ID列表 ------------*/
     subProjectList : function(t){
		var ul="<ul>";
		ul+="<li><a onclick=\"page.chooseChildProjectList(-1)\" id=\"0\" name=\"选择子项目\" href=\"javascript:void(0);\">选择子项目</a></li>";
		for(var i=0;i<page.project_data[t].child.length;i++){
			ul+="<li><a onclick=\"page.chooseChildProjectList("+t+","+i+")\" id=\""+page.project_data[t].child[i].id+"\" name=\""+page.project_data[t].child[i].name+"\" href=\"javascript:void(0);\">"+page.project_data[t].child[i].name+"</a></li>";
		}
		ul+="</ul>";
		$("#sub_id_list").html(ul);
		$(".like_select").click(function(){$(this).parent().find('.select_drop_down').css({visibility: "visible",display: "none"}).show();});
		$(".type_select").hover(
			function(){},
			function(){$(this).find('.select_drop_down').delay(1000).hide();}
		);
    },
	
	chooseChildProjectList : function(t1,t2){
         $('#sub_id_list').css('display', 'none');
		 if(t1==-1){
			$('#sub_id_name').html("选择子项目");
			$('#sub_id').val(0);
		 }
		 else{
			$('#sub_id_name').html(page.project_data[t1].child[t2].name);
			$('#sub_id').val(page.project_data[t1].child[t2].id);
		 }
    },

	
    /*------------ 添加一段代码 ------------*/
    add : function(){
        if($("#parent_id").val()==0)
		{
			message.show("message_div","","请选择项目",4);
			return;
		}
		
		
		var project_id=0;
		if($("#sub_id").val()*1>0)
			project_id=$("#sub_id").val();
		else
			project_id=$("#parent_id").val();
		var data_area=[];
		data_area.push([ "name" , $('#name').val() ]);
		data_area.push([ "info" , $('#info').val() ]);
		data_area.push([ "project_id" , project_id ]);
		data_area.push([ "ident" , $('#ident').val() ]);
		data_area.push([ "frame_flag" , global_type ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'page-add',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:function(feedback){
				if(feedback.ret=="0"){
					message.show("message_div","","添加成功",3,"","window.location.href='page_list.htm?type="+global_type+"'");
				}
				else{
					message.show("message_div","",feedback.msg,4);
				}
			}
        });
    },

	/*------------ 添加一段代码 ------------*/
    addFromFrame : function(t){
		var data_area=[];
		data_area.push([ "frame_id" , t ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'page-addFromFrame',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:function(feedback){
				console.log(feedback);return;
				if(feedback.ret=="0"){
					message.show("message_div","","添加成功",3,"","window.location.href='page_list.htm?type="+global_type+"'");
				}
				else{
					message.show("message_div","",feedback.msg,4);
				}
			}
        });
    },

	
	/*------------ 编辑 ------------*/
    edit : function(){
		var data_area=[];
		data_area.push([ "id" , global_id ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
                url: cgipath+'page-getinfo',type: 'POST',data: data_str,dataType: 'json',timeout: ajax_timeout,error: function(){notify.show(2,"请求数据失败，请刷新页面");},
                success:this.handleedit
        });
    },

     handleedit : function(feedback){
        if(feedback.ret=="0"){
            var record=feedback.record;
			$("#name").val(record.name);
			$("#info").val(record.info);
			$("#ident").val(record.ident);
			
			for(var i=0;i<page.project_data.length;i++){
				if(page.project_data[i].parent.id==record.project_id){
					$("#parent_id").val(page.project_data[i].parent.id);
					$("#parent_id_name").html(page.project_data[i].parent.name);
					return;
				}
				else{
					for(var j=0;j<page.project_data[i].child.length;j++){
						if(page.project_data[i].child[j].id==record.project_id){
							$("#sub_id").val(page.project_data[i].child[j].id);
							$("#sub_id_name").html(page.project_data[i].child[j].name);
							$("#parent_id").val(page.project_data[i].parent.id);
							$("#parent_id_name").html(page.project_data[i].parent.name);
							return;
						}
					}
				}
			}
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	/*------------ 保存一个项目 ------------*/
	update : function(){
        //收集项目信息
		var project_id=0;
		if($("#sub_id").val()*1>0)
			project_id=$("#sub_id").val();
		else
			project_id=$("#parent_id").val();
		var data_area=[];
		data_area.push([ "id" , global_id ]);
		data_area.push([ "name" , $('#name').val() ]);
		data_area.push([ "info" , $('#info').val() ]);
		data_area.push([ "ident" , $('#ident').val() ]);
		data_area.push([ "project_id" , project_id ]);
		data_area.push([ "frame_flag" , 0 ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'page-update',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handleUpdate
        });
    },

    handleUpdate : function (feedback){
        if(feedback.ret=="0"){
			message.show("message_div","","保存成功",3,"","window.location.href='page_manage.htm?&type="+global_type+"';");
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	
	/*------------ 获取一条信息 ------------*/
    getinfoImg : function(){
		var data_area=[];
		data_area.push([ "id" , code_id ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
                url: cgipath+'code-getinfo',type: 'POST',data: data_str,dataType: 'json',timeout: ajax_timeout,error: function(){notify.show(2,"请求数据失败，请刷新页面");},
                success:this.handlGetinfoImg
        });
    },

     handlGetinfoImg : function(feedback){
        if(feedback.ret=="0"){
            $('#photo')[0].src=cgipath+feedback.record.path_img+"?"+Math.random();
			$('#thumb')[0].src=cgipath+feedback.record.path_thumb+"?"+Math.random();
			$('#photo').imgAreaSelect({  handles: true,fadeSpeed: 200, onSelectChange: preview });
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },

	
	 /*------------ 删除项目 ------------*/
	 
	delConfirm:function(id){
		message.show("message_div","","确实要删除吗？",2,"","page.del("+id+");");
	},
	
    del : function(id){
		var data_str="&id="+id;
        $.ajax({
            url:cgipath + 'page-del',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handledel
        });
    },

    handledel : function (feedback){
        if(feedback.ret=="0"){
            message.show("message_div","","删除成功",3,"","page.showlist();");
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	
	 /*------------ 保存截图 ------------*/
    adjustImg : function(){
		var data_area=[];
		data_area.push([ "code_id" , code_id ]);
		data_area.push([ "x" , x ]);
		data_area.push([ "y" , y ]);
		data_area.push([ "w" , w ]);
		data_area.push([ "h" , h ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'image-adjust',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handladjustImg
        });
    },

    handladjustImg : function (feedback){
        if(feedback.ret=="0"){
            history.go(0);
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	
	 /*------------ 重新生成截图 ------------*/
	createImg : function(){
		var data_area=[];
		data_area.push([ "code_id" , code_id ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'code-snapshot',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handlrecreateImg
        });
    },

    handlrecreateImg : function (feedback){
        if(feedback.ret=="0"){
            history.go(0);
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    }

}




var pageManage = {
	init:function(){
		$("#btn_filter").click(function(){pageManage.filter();});
		$("#btn_reset").click(function(){pageManage.filterReset();});
		if(global_type=="1"){
			$('#page_title').html("<i class=\"ico ico_manage\"></i><span>框架列表</span>");
		}
		else{
			$('#page_title').html("<i class=\"ico ico_manage\"></i><span>页面列表</span>");
		}
	},
	
	search:function(){
		$('#parent_id_name').html("所有"+code_text);
		$('#parent_id').val(0);
		this.search_data=[];
		this.page=1;
		var search_text=$("#search_text").val();
		this.search_data.push([ "search_flag" , 1 ]);
		this.search_data.push([ "search_data" , search_text ]);
		this.showlist();
	},
	
	filter:function(){
		var project_id=$('#parent_id').val();
		if($("#sub_id").val()!=-1)project_id=$('#sub_id').val();
		this.search_data=[];
		this.page=1;
		if(project_id*1!=-1){
			this.search_data.push([ "search_flag" , 0 ]);
			this.search_data.push([ "project_id" , project_id ]);
		}
		this.showlist();
	},
	
	filterReset:function(){
		$('#parent_id_name').html("所有项目");
		$('#parent_id').val(0);
		$('#sub_id_name').html("选择子项目");
		$('#sub_id').val(0);
		this.search_data=[];
		this.page=1;
		this.showlist();
	},
	
    /*------------ 获取所有根项目信息 ------------*/
	search_data:[],
	page:1,//第几页
	reqnum:5,//每页显示多少条
	order:"id",//排序字段
	desc:1,//反序,0或空正常排序，1反序
	page_nums:0,//总页数
		
    showlist : function(){
		var data_area=[];
		var data_area=[];
		data_area.push([ "page" , this.page ]);
		//data_area.push([ "reqnum" , this.reqnum ]);
		data_area.push([ "order" , this.order ]);
		data_area.push([ "desc" , this.desc ]);
		data_area.push([ "desc" , this.desc ]);
		if(this.search_data.length>0)
			data_area=data_area.concat(this.search_data);
		
		var data_str=functions.requestToString(data_area);
		if(global_type=="1")url_parm='page-frameShowlist';
		else url_parm='page-showlist';
        $.ajax({
                url: cgipath+url_parm, type: 'POST',data: data_str,dataType: 'json', timeout: ajax_timeout,error: function(){notify.show(2,"请求数据失败，请刷新页面");},
                success:this.handleShowlist
        });
    },
	
     handleShowlist : function(feedback){
        if(feedback.ret=="0"){
            //显示项目列表
            var listdata=feedback.listdata;
			var innerhtml="";
            for(var i=0;i<listdata.length;i++){
				innerhtml+="<li>";
				if(listdata[i].thumb!=null)innerhtml+="<a target=\"_blank\" href=\""+(cgipath+listdata[i].addr)+"\" class=\"img\"> <img src=\""+(cgipath+listdata[i].thumb)+"?"+Math.floor(Math.random()*10000)+"\" alt=\"\"></a>";
				else innerhtml+="<a href=\"javascript:void(0);\"  class=\"img\"> <img src=\"css/sample/no_img.png\" alt=\"\"></a>";
				innerhtml+="<div class=\"framework_mask\">";
				if(global_type=="1")
					innerhtml+="<p class=\"framework_op\"><a target='_blank' href=\"custom.htm?page_id="+listdata[i].id+"\" onclick=\"\">编辑框架</a><a href=\"custom.htm?frame_id="+listdata[i].id+"\" target=\"_blank\">创建页面</a> </p>";
				else{
					innerhtml+="<p class=\"framework_op\"><a target='_blank' href=\"custom.htm?page_id="+listdata[i].id+"\" onclick=\"\">编辑页面</a>";
					if(listdata[i].thumb!=null)innerhtml+="<a href=\"javascript:void(0)\" onclick=\"pageManage.createConfirm("+listdata[i].id+")\">生成页面</a></p>";
				}
				innerhtml+="<p class=\"framework_name\"><strong>"+listdata[i].name+"</strong></p>";
				innerhtml+="</div>";
				innerhtml+="</li>";
            }
			if(global_type==1)
				innerhtml+="<li><a href=\"page.htm?type=1\" class=\"img\" title=\"添加新框架\"> <img src=\"css/sample/blog_add.png\"></a></li>";
			else
				innerhtml+="<li><a href=\"page.htm\" class=\"img\" title=\"添加新页面\"> <img src=\"css/sample/blog_add.png\"></a></li>";
			//翻页组件
			pageManage.page_nums=Math.ceil(feedback.nums/pageManage.reqnum);
			if(pageManage.page_nums<pageManage.page)pageManage.page=pageManage.page_nums;//防止page_nums等于0的情况
			$("#page_nums").html(pageManage.page+"/"+pageManage.page_nums);
			if(pageManage.page==1)
				$("#page_up").removeClass("ico_page_left").addClass("ico_page_left_n");
			else
				$("#page_up").removeClass("ico_page_left_n").addClass("ico_page_left");
			if(pageManage.page_nums==pageManage.page)
				$("#page_down").removeClass("ico_page_right").addClass("ico_page_right_n");
			else
				$("#page_down").removeClass("ico_page_right_n").addClass("ico_page_right");
			
			$("#list_area").html(innerhtml);
			$("#list_area").find("li").mouseover(function(){$(this).addClass("current")});
			$("#list_area").find("li").mouseout(function(){$(this).removeClass("current")});
        }
        else{
             message.show("message_div","",feedback.msg,4);
        }
    },
	
	list_page:function(t,order){
		if(order!=undefined && order!="")
		{
			page.order=order;
			if(page.desc*1==1)page.desc=0;
			else page.desc=1;
		}
	
		page.page=page.page-(-1)*t;
		if(page.page<=0)page.page=1;
		else if(page.page>page.page_nums) page.page=page.page_nums;
		page.showlist();
	},
	
	

	
	createConfirm:function(id){
		message.show("message_div","","本操作将会按照 该页面所在项目的项目类型的目录结构 生成相应的页面、样式、图片等。<BR><font style=\"color:#D13B3B\">确认生成吗?</span>",2,"","pageManage.create("+id+");");
	},
	
    create : function(id){
		notify.show(1,"正在生成页面，请稍候");
		var data_str="&id="+id;
        $.ajax({
            url:cgipath + 'page-create',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:function(feedback){
				if(feedback.ret=="0"){
					notify.close();
					message.show("message_div","","生成成功",3,"","window.location.reload();");
				}
				else{
					message.show("message_div","",feedback.msg,4);
					notify.close();
				}
			
			}
        });
    },

	
	
	 /*------------ 删除项目 ------------*/
	 
	delConfirm:function(id){
		message.show("message_div","","确实要删除吗？",2,"","page.del("+id+");");
	},
	
    del : function(id){
		var data_str="&id="+id;
        $.ajax({
            url:cgipath + 'page-del',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handledel
        });
    },

    handledel : function (feedback){
        if(feedback.ret=="0"){
            message.show("message_div","","删除成功",3,"","window.location.reload();");
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	
	/*------------ 模块、组件转换 ------------*/
	transition : function(t){
        //收集项目信息
		var data_area=[];
		data_area.push([ "id" , t ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'code-transition',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handletransition
        });
    },

    handletransition : function (feedback){
		console.log(feedback);
        if(feedback.ret=="0"){
			message.show("message_div","","转换成功",3,"","code.showlist();");
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	 /*------------ 保存截图 ------------*/
    adjustImg : function(){
		var data_area=[];
		data_area.push([ "code_id" , code_id ]);
		data_area.push([ "x" , x ]);
		data_area.push([ "y" , y ]);
		data_area.push([ "w" , w ]);
		data_area.push([ "h" , h ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'image-adjust',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handladjustImg
        });
    },

    handladjustImg : function (feedback){
        if(feedback.ret=="0"){
            history.go(0);
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    },
	
	 /*------------ 重新生成截图 ------------*/
	createImg : function(){
		var data_area=[];
		data_area.push([ "code_id" , code_id ]);
		var data_str=functions.requestToString(data_area);
        $.ajax({
            url:cgipath + 'code-snapshot',type:'POST',data:data_str,dataType:'json',timeout: ajax_timeout,error:function () {notify.show(2,"请求数据失败，请刷新页面");},
            success:this.handlrecreateImg
        });
    },

    handlrecreateImg : function (feedback){
        if(feedback.ret=="0"){
            history.go(0);
        }
        else{
            message.show("message_div","",feedback.msg,4);
        }
    }
	
	

}






